﻿using DEL.Dzb;
using DEL.Gzh;
using DEL.Sys;
using DEL.Webmonitor;
using Microsoft.EntityFrameworkCore;

namespace DEL
{
    public class EFDbContext : DbContext
    {        
        //采用依赖注入的方式
        //public EFDbContext(DbContextOptions options) : base(options)
        //{            
        //}

        //变量名称与数据库表名称一致,不区分大小写        
        public DbSet<InfoHit> Webm_InfoHit { get; set; }
        public DbSet<InfoOriginal> Webm_InfoOriginal { get; set; }
        public DbSet<Keyword> Webm_Keyword { get; set; }
        public DbSet<KeywordType1> Webm_KeywordType1 { get; set; }
        public DbSet<KeywordType2> Webm_KeywordType2 { get; set; }
        public DbSet<Website> Webm_Website { get; set; }
        public DbSet<WebsiteJK> Webm_WebsiteJK { get; set; }
        public DbSet<WebsiteType> Webm_WebsiteType { get; set; }

        public DbSet<User> Sys_User { get; set; }
        public DbSet<Department> Sys_Department { get; set; }
        public DbSet<Menu> Sys_Menu { get; set; }
        public DbSet<Role> Sys_Role { get; set; }
        public DbSet<RoleMenu> Sys_RoleMenu { get; set; }
        public DbSet<UserRole> Sys_UserRole { get; set; }

        public DbSet<XSXXType> Gzh_XSXXType { get; set; }
        public DbSet<XSXXInfo> Gzh_XSXXInfo { get; set; }
        public DbSet<XSXXClue> Gzh_XSXXClue { get; set; }
        public DbSet<Police> Gzh_Police { get; set; }
        public DbSet<SQJD> Gzh_SQJD { get; set; }
        public DbSet<TSJY> Gzh_TSJY { get; set; }
        public DbSet<WFJB> Gzh_WFJB { get; set; }
        public DbSet<YWLB> Gzh_YWLB { get; set; }
        public DbSet<YW> Gzh_YW { get; set; }
        public DbSet<YYSM> Gzh_YYSM { get; set; }
        public DbSet<YYXF> Gzh_YYXF{ get; set; }
        public DbSet<ZLYJ> Gzh_ZLYJ{ get; set; }

        public DbSet<Party> Dzb_Party { get; set; }
        public DbSet<PartyMember> Dzb_PartyMember { get; set; }

        //执行SqlDataReader.Read之后，如果还想用另一个SqlCommand执行Insert或者Update操作的话，会得到一个错误提示：
        //There is already an open DataReader associated with this Command which must be closed first.，然后一般就会产生数据保存失败的异常。
        //解决方法是在ConnectionString中加上一个参数“MultipleActiveResultSets”, 将其值设置为true
        private const string ConnectionString = "Data Source=60.160.21.158,1433;Initial Catalog=ybsoft;Integrated Security=False;Persist Security Info=False;User ID=sa;Password=Yuan1977;MultipleActiveResultSets=True";

        //EF Core1.0 生成的分页语句中使用了 Featch Next。这个语句只有在SqlServer2012的时候才能使用。
        //EF Core 1.0 在sqlserver2008分页的时候需要指定用数字分页。必须使用UseRowNumberForPaging()
        //参考http://stackoverflow.com/questions/37403188/userownumberforpaging-is-not-a-valid
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseSqlServer(ConnectionString);
            
        }        
    }
}
